
// let nickname = '四营的姑娘' ;

// 执行器接受两个函数作参数
let executor = function( resolve , reject ){
    console.log( nickname ); // 当这里抛出异常时会调用 reject 并将异常对象传递给 reject 函数
    resolve( '已兑现' ); // 如果上一行发生异常，则后续代码都不会再执行
    reject( '已拒绝' );
}

// 创建 Promise 实例时必须通过参数指定一个 执行器(executor)
let p = new Promise( executor );

let onResolved = function(){
    console.log( '兑现' );
}

let onRejected = function( e ){
    console.log( '拒绝' , e.message );
}

let resolve = function(...params) {
    onResolved();
}

let reject = function(error){
    // console.log( error );
    onRejected( error );
}

p.then( resolve , reject );